// Logic_Expression.cpp: implementation of the Logic_Expression class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "Logic_Expression.h"
#include "Simple_Expression.h"
#include "_Logic_Expression.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

Logic_Expression::Logic_Expression()
{
	m_pLogic = NULL;
}

Logic_Expression::~Logic_Expression()
{
	delete m_pLogic;
}

BOOL Logic_Expression::Interpret()
{
/*	_Logic_Expression *pExpression = NULL;
	return DualityOperIterpret<Logic_Expression, Logic_Expression, _Logic_Expression>(pExpression, this, 2 , CString(_T("&&")), CString(_T("||")));*/


	CString strTemp;
	ComplierNote* pNote = new Simple_Expression;
	pNote->SetOwner(this);
	LeftNote(pNote);

	if(!pNote->Interpret())
	{
		this->ErrorInfo(pNote->ErrorInfo());
		return FALSE;
	}
	
//	while(true)
	{
		strTemp = AAnalyzer()->GetCurSymbol();
		if(strTemp.IsEmpty() || strTemp == _T(")") || strTemp == _T(";") || strTemp == _T(","))
			return TRUE;
		
		m_pOperatorNote = new LogicNote;
		m_pOperatorNote->SetOwner(this);
		if(!m_pOperatorNote->Interpret())
		{
			this->ErrorInfo(pNote->ErrorInfo());
			return FALSE;
		}
		
		pNote = new Simple_Expression;
		pNote->SetOwner(this);
		RightNote(pNote);
		
		if(!pNote->Interpret())
		{
			this->ErrorInfo(pNote->ErrorInfo());
			return FALSE;
		}
	}
	return TRUE;
}

Variable Logic_Expression::Execute()
{
	if(m_pOperatorNote != NULL)
	{
		return m_pOperatorNote->Execute();
	}
	else
	{
		return LeftNote()->Execute();
	}
}
